<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/sys/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ include file="/WEB-INF/adminui/include/css.jsp" %>
<title>农资管理列表</title>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
	<div class="row">
		<div class="col-sm-2" style="width:18.66666667%">
			<div class="ibox ibox-body">
				<div class="ibox-title">
					<h5>选择园区</h5>
				</div>
				<div class="ibox-content">
					<div id="jstree"></div>
				</div>
			</div>
		</div>
		<div class="col-sm-9">
			<div class="ibox">
				<div class="ibox-body">
					<div class="fixed-table-toolbar">
						<div id="toolbar" class="columns pull-left">
						
						<!-- 种植-种子 权限 -->
						<c:if test="${pType==1 && mType==1}">
							<qx:perm code="repertory_zz_add">
							<button type="button" class="btn btn-primary" onclick="add()" uilist-prem="repertory_zz_add">
								<i class="fa fa-plus hidden" aria-hidden="true"></i>添加种子
							</button>
							</qx:perm>
						</c:if>
						<!-- 种植-肥料 权限 -->
						<c:if test="${pType==1 && mType==2}">
							<qx:perm code="repertory_fl_add">
							<button type="button" class="btn btn-primary" onclick="add()" uilist-prem="repertory_fl_add">
								<i class="fa fa-plus hidden" aria-hidden="true"></i>添加肥料
							</button>
							</qx:perm>
						</c:if>
						<!-- 种植-农药 权限 -->
						<c:if test="${pType==1 && mType==3}">
							<qx:perm code="repertory_ny_add">
							<button type="button" class="btn btn-primary" onclick="add()" uilist-prem="repertory_ny_add">
								<i class="fa fa-plus hidden" aria-hidden="true"></i>添加农药
							</button>
							</qx:perm>
						</c:if>
						<!-- 养殖-饲料 权限 -->
						<c:if test="${pType==2 && mType==1}">
							<qx:perm code="repertory_sl_add">
							<button type="button" class="btn btn-primary" onclick="add()" uilist-prem="repertory_sl_add">
								<i class="fa fa-plus hidden" aria-hidden="true"></i>添加饲料
							</button>
							</qx:perm>
						</c:if>
						<!-- 养殖-药品 权限 -->
						<c:if test="${pType==2 && mType==2}">
							<qx:perm code="repertory_yp_add">
							<button type="button" class="btn btn-primary" onclick="add()" uilist-prem="repertory_yp_add">
								<i class="fa fa-plus hidden" aria-hidden="true"></i>添加药品
							</button>
							</qx:perm>
						</c:if>
							
						</div>
						<c:if test="${pType==1}">
						<div class="columns pull-right" style="margin-left:5px;">
							<button class="btn btn-success" onclick="doexport()">导出Excel</button>
						</div>
						</c:if>
						<div class="columns pull-right">
							<button class="btn btn-success" onclick="UiList.loadTable()">查询</button>
						</div>
						<div class="columns pull-right col-md-2 nopadding">
							<input id="searchName" type="text" class="form-control" placeholder="按名称查询">
						</div>
					</div>
					<table id="dataTable" data-mobile-responsive="true">
					</table>
				</div>
			</div>
		</div>
	</div>
</div>
<%@ include file="/WEB-INF/adminui/include/script.jsp" %>
<script type="text/javascript">
$(function(){
	UiList.render({
		treeUrl: '${path}/parkjstree/menudata.json?module=park',
		tableConfig:{
			url: "${path}/repertory/listdata.json?pType=${pType}&mType=${mType}",
			idfield: 'repertoryid',
			columns: [
				{checkbox : true},
				{field : 'producer', title : '生产商'},
				{field : 'materialName', title : '农资名称'},
				{field : 'batchNum', title : '批号'},
				{field : 'ingredient', title : '成分'},
				{field : 'phi', title : '安全间隔期'},
				{field : 'amount', title : '总数量'},
				{field : 'repertory_num', title : '库存数量'},
				{field : 'used_num', title : '已使用数量'},
				{field : 'repertoryid', title : '操作', align : 'center', formatter : function(value, row, index) {
					var s = '';
					var vpType = '${pType}';
					var vmType = '${mType}';
					if(vpType==1 && vmType==1){// 种植-种子 权限
						<qx:perm code="repertory_zz_edit">
						s += '<a class="btn btn-primary btn-sm" href="javascript:;" title="修改种子" onclick="edit(\''+value+'\')">修改种子</a> ';
						</qx:perm>
						<qx:perm code="repertory_zz_account">
						s += '<a class="btn btn-warning btn-sm" href="javascript:;" title="流水账管理" onclick="account(\''+value+'\')">流水账管理</a> ';
						</qx:perm>
						<qx:perm code="repertory_zz_del">
						s += '<a class="btn btn-danger btn-sm" href="javascript:;" title="删除种子" onclick="del(\''+value+'\')">删除种子</a>';
						</qx:perm>
					}else if(vpType==1 && vmType==2){// 种植-肥料 权限
						<qx:perm code="repertory_fl_edit">
						s += '<a class="btn btn-primary btn-sm" href="javascript:;" title="修改肥料" onclick="edit(\''+value+'\')">修改肥料</a> ';
						</qx:perm>
						<qx:perm code="repertory_fl_account">
						s += '<a class="btn btn-warning btn-sm" href="javascript:;" title="流水账管理" onclick="account(\''+value+'\')">流水账管理</a> ';
						</qx:perm>
						<qx:perm code="repertory_fl_del">
						s += '<a class="btn btn-danger btn-sm" href="javascript:;" title="删除肥料" onclick="del(\''+value+'\')">删除肥料</a>';
						</qx:perm>
					}else if(vpType==1 && vmType==3){// 种植-农药 权限
						<qx:perm code="repertory_ny_edit">
						s += '<a class="btn btn-primary btn-sm" href="javascript:;" title="修改农药" onclick="edit(\''+value+'\')">修改农药</a> ';
						</qx:perm>
						<qx:perm code="repertory_ny_account">
						s += '<a class="btn btn-warning btn-sm" href="javascript:;" title="流水账管理" onclick="account(\''+value+'\')">流水账管理</a> ';
						</qx:perm>
						<qx:perm code="repertory_ny_del">
						s += '<a class="btn btn-danger btn-sm" href="javascript:;" title="删除农药" onclick="del(\''+value+'\')">删除农药</a>';
						</qx:perm>
					}else if(vpType==2 && vmType==1){// 养殖-饲料 权限
						<qx:perm code="repertory_sl_edit">
						s += '<a class="btn btn-primary btn-sm" href="javascript:;" title="修改饲料" onclick="edit(\''+value+'\')">修改饲料</a> ';
						</qx:perm>
						<qx:perm code="repertory_sl_account">
						s += '<a class="btn btn-warning btn-sm" href="javascript:;" title="流水账管理" onclick="account(\''+value+'\')">流水账管理</a> ';
						</qx:perm>
						<qx:perm code="repertory_sl_del">
						s += '<a class="btn btn-danger btn-sm" href="javascript:;" title="删除饲料" onclick="del(\''+value+'\')">删除饲料</a>';
						</qx:perm>
					}else if(vpType==2 && vmType==2){// 养殖-药品 权限
						<qx:perm code="repertory_yp_edit">
						s += '<a class="btn btn-primary btn-sm" href="javascript:;" title="修改药品" onclick="edit(\''+value+'\')">修改药品</a> ';
						</qx:perm>
						<qx:perm code="repertory_yp_account">
						s += '<a class="btn btn-warning btn-sm" href="javascript:;" title="流水账管理" onclick="account(\''+value+'\')">流水账管理</a> ';
						</qx:perm>
						<qx:perm code="repertory_yp_del">
						s += '<a class="btn btn-danger btn-sm" href="javascript:;" title="删除药品" onclick="del(\''+value+'\')">删除药品</a>';
						</qx:perm>
					}
					
					return s;
				}}
			]
		},
		tableParams: function(){//搜索条件
			return {search: $("#searchName").val()};
		}
	});
	
});

function add(){
	UiList.open('${path}/repertory/add.do?pType=${pType}&mType=${mType}', '添加农资信息', {refresh:true});
}
function account(id){
	UiList.open('${path}/repertory/account.do?repertoryid='+id, '流水账管理', {full:true});
}
function del(id){
	UiList.dialog('${path}/repertory/delete.json?repertoryid='+id, '您确定要删除选中的农资信息吗？', '删除农资信息成功.', {refresh:true,useTableData:false});
}
function edit(id){
	UiList.open('${path}/repertory/edit.do?repertoryid='+id, '修改农资信息', {refresh:true});
}

function doexport(){
	var node = UiList.getSelectedTreeNode();
	var search = $("#searchName").val();
	var url = "${path}/repertory/doexport.do?pType=${pType}&mType=${mType}&datatype="+node.type+"&leftdata="+node.id;
	if(search){
		url = url + "&search="+encodeURIComponent(search);
	}
	window.open(url, '_blank');
}

</script>
</body>
</html>